<template>
  <div class="career-prospects">
    <div class="left">
      <TitleHeader name="就业方向薪酬分布" />
      <div class="chart-container">
        <ColumnChart
          v-if="salaryWorkDirectionChart.dataX?.length > 0"
          :xAxisData="salaryWorkDirectionChart.dataX"
          :seriesData="salaryWorkDirectionChart.dataY"
        />
        <Empty v-else />
      </div>
    </div>
    <div class="right">
      <TitleHeader name="就业城市热度" />
      <div class="chart-container">
        <ColumnCityChart
          v-if="getHotCitysChart.dataX?.length > 0"
          :xAxisData="getHotCitysChart.dataX"
          :seriesData="getHotCitysChart.dataY"
        />
        <Empty v-else />
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue';
import TitleHeader from './TitleHeader.vue';
import ColumnChart from '@/components/ColumnChart/index.vue';
import ColumnCityChart from '@/components/ColumnCityChart/index.vue';
import { getPositionSalary, getHotCitys } from '@/api/majorSearch';
import Empty from '@/components/empty.vue';

const props = defineProps({
  positionTagId: {
    type: String,
    default: '',
  },
});
const salaryWorkDirectionChart = ref({});

const getPositionSalaryFn = async () => {
  const params = {
    positionTagId: props.positionTagId,
    regionIds: '100000',
  };
  const res = await getPositionSalary(params);
  if (res.code == 200) {
    let result = {
      dataX: [],
      dataY: [],
    };
    res.data.forEach((item) => {
      result.dataX.push(item.xTitle);
      result.dataY.push(Math.floor(item.yValue));
    });
    salaryWorkDirectionChart.value = result;
  }
};
const getHotCitysChart = ref({});

const getHotCitiesFn = async () => {
  const params = {
    positionTagId: props.positionTagId,
  };
  const res = await getHotCitys(params);
  if (res.code == 200) {
    let result = {
      dataX: [],
      dataY: [],
    };
    res.data.forEach((item) => {
      result.dataX.push(item.xTitle);
      result.dataY.push(Math.floor(item.yValue));
    });
    getHotCitysChart.value = result;
  }
};
watch(
  () => props.positionTagId,
  (nawVal) => {
    getPositionSalaryFn();
    getHotCitiesFn();
  },
  { deep: true }
);
onMounted(() => {
  getPositionSalaryFn();
  getHotCitiesFn();
});
</script>

<style lang="scss" scoped>
.career-prospects {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  .left,
  .right {
    padding: 40px;
    width: 50%;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    .chart-container {
      width: 100%;
      flex: 1;
      min-height: 0;
    }
  }
}
</style>
